<?php
class Approver extends Admin_Controller
{
	
	function __construct()
	{
		parent::__construct();
		$this->load->model('approver_model','approver');
	}
	
	function index($fund_id)
	{
		$user = login_data();
		$this->load->model('voucher/fund_model','fund');
		$data['fund'] = $this->fund->get_row($fund_id);
		$data['rs'] = $this->db->getRow('select * from approves where fund_id = '.$fund_id.' and agency_id = '.$user['agency_id']);
		dbConvert($data['rs']);
		$this->template->append_metadata(js_validate());
		$this->template->build('approver_index',$data);
	}
	
	function save()
	{
		if($_POST)
		{
			$user = login_data();
			add_log('แก้ไขชื่อผู้อนุมัติ');
			$_POST['id'] = $this->db->getOne('select id from approves where fund_id = '.$_POST['fund_id'].' and agency_id = '.$user['agency_id']);
			$_POST['agency_id'] = $user['agency_id'];
			$this->approver->save($_POST);
			set_notify('success', lang('save_data_complete'));
		}
		redirect($_SERVER['HTTP_REFERER']);
	}
	
}
?>